﻿package
{
	import flash.display.*;
	import flash.events.*;
	
	public class SimLife extends MovieClip
	{
		// Define Avarta Action String
		const START:String = "start";
		const STOP:String = "stop";
		const JUMP:String = "jump";
		const FALL:String = "fall";
		
		//button variables
		/*public var startBtn:StartBtn;
		public var stopBtn:StopBtn;
		public var jumpBtn:JumpBtn;
		public var fallBtn:FallBtn;*/
		//avarta variable
		public var myAvarta:Avarta;
		//wall area variable
		public var wall:Wall;
		//floor area variable
		public var floor:Floor;
		//FurnitureArea variable
		public var funitureArea:FurnitureArea;
		//UI Layer
		public var uiLayer:UILayer;
		
		//customized events
		var simlifeEventDispatcher:SimLifeEventDispatcher;
		var simlifeEvent:SimLifeEvents;
		
		function SimLife()
		{
			
			UIConfiguration.InitData();
			
			wall = new Wall();
			floor = new Floor();
			funitureArea = new FurnitureArea();
			myAvarta = new Avarta();
			uiLayer = new UILayer();
			
			simlifeEventDispatcher = new SimLifeEventDispatcher();
			//simlifeEvent = new SimLifeEvents("null");
			
			/*startBtn = StartButton;
			stopBtn = StopButton;
			jumpBtn = JumpButton;
			fallBtn = FallButton;*/
			
			myAvarta.x = 300;
			myAvarta.y = 300;
			myAvarta.width = 60;
			myAvarta.height = 100;
			
			wall.x = 0;
			wall.y = 0;
			
			//Avarta Event Listener
			myAvarta.addEventListener(MouseEvent.CLICK, myAvarta.onAvartaClick);
			myAvarta.addEventListener(SimLifeEvents.PETMOVE, myAvarta.onAvartaMove);
			
			
			//simlifeEventDispatcher.addEventListener(SimLifeEvents.CONTROL_TYPE, myAvarta.onActionHandler);
			
			//Buttons Event Listener
			/*startBtn.addEventListener(MouseEvent.CLICK, onStartBtnClick);
			stopBtn.addEventListener(MouseEvent.CLICK, onStopBtnClick);
			jumpBtn.addEventListener(MouseEvent.CLICK, onJumpBtnClick);
			fallBtn.addEventListener(MouseEvent.CLICK, onFallBtnClick);*/
			
			
			addChild(wall);
			addChild(floor);
			addChild(funitureArea);
			addChild(myAvarta);
			addChild(uiLayer);
			
			myAvarta.stop();
		}
		
		function onStartBtnClick(event:MouseEvent)
		{
			//simlifeEvent.action = START;
			//var simlifeEvent:SimLifeEvents = new SimLifeEvents(START);
			simlifeEventDispatcher.doAction(START);
			
		}
		
		function onStopBtnClick(event:MouseEvent)
		{
			//simlifeEvent.action = STOP;
			//var simlifeEvent:SimLifeEvents = new SimLifeEvents(STOP);
			simlifeEventDispatcher.doAction(STOP);
	
		}
		
		function onJumpBtnClick(event:MouseEvent)
		{
			//simlifeEvent.action = JUMP;
			//var simlifeEvent:SimLifeEvents = new SimLifeEvents(JUMP);
			simlifeEventDispatcher.doAction(JUMP);
			
		}
		
		function onFallBtnClick(event:MouseEvent)
		{
			//simlifeEvent.action = FALL;
			//var simlifeEvent:SimLifeEvents = new SimLifeEvents(FALL);
			simlifeEventDispatcher.doAction(FALL);
			
		}
		
	}
			
}
			